package com.jiayuge.server.service.impl;

import com.jiayuge.server.common.entity.RespBean;
import com.jiayuge.server.pojo.Position;
import com.jiayuge.server.mapper.PositionMapper;
import com.jiayuge.server.service.IPositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jiayu.Yang
 * @since 2021-11-15
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements IPositionService {

    /**
     * 功能: 添加职位  |数据库: 增  查
     * * @param position
     * @return {@link RespBean}
     * @Date 2021/11/23
     * @author jiayu.Yang
     */
    @Override
    public RespBean addPosition(Position position) {
        List<Position> positions = super.list();
        List<String> positionNames = positions.stream().map(position1 -> position1.getName()).collect(Collectors.toList());
        if (positionNames.contains(position.getName())){
            return RespBean.error("添加失败，职位信息已存在");
        }
        if (super.save(position)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
}
